package service

import (
	"errors"
	"gin-epg/internal/app/entity"
	"gin-epg/internal/app/mapper"
	"log"
)

// FindUserByName 根据用户名查找用户
func FindUserByName(username string) (*entity.User, error) {
	// 调用 mapper 获取用户
	user, err := mapper.GetUserByName(username)
	if err != nil {
		// 处理错误
		log.Printf("Failed to find user by name %s: %v", username, err)
		return nil, err
	}

	// 检查用户是否存在
	if user == nil {
		return nil, errors.New("用户不存在")
	}

	return user, nil
}
